# demo04_gen.py   yield: 函数的暂停
def my_gen():
    a = 100
    yield a
    b = "hello"
    yield b
    c = [1, 2, 3]
    yield c
gen = my_gen()
for item in gen:  # for循环获取生成器数据不会报错
    print(item)
print("============================")
for item in gen:  # 生成器中的数据只能获取一次,不打印数据
    print(item)
# print(gen)  # <generator object my_gen at 0x7f392d910a98>
# print(gen.__next__())  # 100
# print(gen.__next__())  # hello
# print(gen.__next__())  # [1, 2, 3]
# print(gen.__next__()) 报错




# return: 表示函数的终止
# def my_func():
#     a = 100
#     return a
#     b = "hello"
#     return b
#
# result = my_func()  # 调用函数
# print(result)  # 100
